/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.crm.sopm.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import merlion.common.entity.Staff;
import merlion.crm.slcm.entity.Customer;
import merlion.crm.slcm.entity.SalesLead;
import merlion.mrp.ppm.entity.Product;

/**
 *
 * @author Zhou Hong
 */
@Entity
public class RequestForQuotation implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String rfqNumber;
    @ManyToOne(targetEntity=SalesLead.class, cascade={CascadeType.PERSIST,CascadeType.MERGE}, fetch=FetchType.EAGER)
    private SalesLead salesLead;
    @ManyToOne(targetEntity = Customer.class, cascade = {CascadeType.PERSIST,CascadeType.MERGE}, fetch = FetchType.EAGER)
    private Customer customer;
    private Timestamp rfqDate;
    private String comments;
    private String dateStr;
    private Boolean currency;
    @OneToMany(targetEntity = ItemLine.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
    private Collection<ItemLine> orderItems = new ArrayList<ItemLine>();
    @ManyToOne(targetEntity = Staff.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
    private Staff customerExecutive;
    

      public RequestForQuotation() {
        for (int i = 0; i < 4; i++){
            ItemLine newItem = new ItemLine();
            newItem.setProduct(new Product(i));
            orderItems.add(newItem);
        }
        salesLead = new SalesLead();
        rfqDate = new Timestamp(System.currentTimeMillis());
        dateStr = rfqDate.toString();
    }
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof RequestForQuotation)) {
            return false;
        }
        RequestForQuotation other = (RequestForQuotation) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "merlion.crm.sopm.entity.RequestForQuotation[ id=" + id + " ]";
    }

    /**
     * @return the salesLead
     */
    public SalesLead getSalesLead() {
        return salesLead;
    }

    /**
     * @param salesLead the salesLead to set
     */
    public void setSalesLead(SalesLead salesLead) {
        this.salesLead = salesLead;
    }

    /**
     * @return the customer
     */
    public Customer getCustomer() {
        return customer;
    }

    /**
     * @param customer the customer to set
     */
    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    /**
     * @return the rfqDate
     */
    public Timestamp getRfqDate() {
        return rfqDate;
    }

    /**
     * @param rfqDate the rfqDate to set
     */
    public void setRfqDate(Timestamp rfqDate) {
        this.rfqDate = rfqDate;
    }

    /**
     * @return the comments
     */
    public String getComments() {
        return comments;
    }

    /**
     * @param comments the comments to set
     */
    public void setComments(String comments) {
        this.comments = comments;
    }

    /**
     * @return the dateStr
     */
    public String getDateStr() {
        return dateStr;
    }

    /**
     * @param dateStr the dateStr to set
     */
    public void setDateStr(String dateStr) {
        this.dateStr = dateStr;
    }

    /**
     * @return the orderItems
     */
    public Collection<ItemLine> getOrderItems() {
        return orderItems;
    }

    /**
     * @param orderItems the orderItems to set
     */
    public void setOrderItems(Collection<ItemLine> orderItems) {
        this.orderItems = orderItems;
    }

    /**
     * @return the customerExecutive
     */
    public Staff getCustomerExecutive() {
        return customerExecutive;
    }

    /**
     * @param customerExecutive the customerExecutive to set
     */
    public void setCustomerExecutive(Staff customerExecutive) {
        this.customerExecutive = customerExecutive;
    }

    /**
     * @return the rfqNumber
     */
    public String getRfqNumber() {
        return rfqNumber;
    }

    /**
     * @param rfqNumber the rfqNumber to set
     */
    public void setRfqNumber(String rfqNumber) {
        this.rfqNumber = rfqNumber;
    }

    /**
     * @return the currency
     */
    public Boolean getCurrency() {
        return currency;
    }

    /**
     * @param currency the currency to set
     */
    public void setCurrency(Boolean currency) {
        this.currency = currency;
    }
}
